.386
.model flat, stdcall
option casemap :none

	include	\masm32\include\windows.inc
	include \masm32\include\kernel32.inc
	include \masm32\include\user32.inc
	include \masm32\include\gdi32.inc

	includelib \masm32\lib\kernel32.lib
	includelib \masm32\lib\user32.lib
	includelib \masm32\lib\gdi32.lib
	
	MainProc		proto :DWORD, :DWORD, :DWORD, :DWORD

.data
	szConfirm		db "Hello World", 0
	szAppName		db "Mirroring test", 0
		
.data?
	hInstance		HINSTANCE ?
	CommandLine		LPSTR ?
	
.code
start:
	invoke	GetModuleHandle, NULL
	mov	hInstance, eax
	invoke	GetCommandLine
	mov	CommandLine, eax
	invoke DialogBoxParam, hInstance, 1001, 0, addr MainProc, 0
	invoke	ExitProcess, eax
	
MainProc proc uses esi edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL rcDialog:RECT
LOCAL rcControl:RECT
LOCAL hControl:HWND

	.if uMsg == WM_INITDIALOG
		invoke LoadIcon, hInstance, 2001
		invoke SendMessage, hWnd, WM_SETICON, 0, eax
	.elseif uMsg == WM_COMMAND
		.if wParam == 1003
			invoke GetWindowLong, hWnd, GWL_EXSTYLE
			or eax, WS_EX_LAYOUTRTL
			invoke SetWindowLong, hWnd, GWL_EXSTYLE, eax
			invoke InvalidateRect, hWnd, NULL, TRUE
			invoke MessageBox, hWnd, addr szConfirm, addr szAppName, MB_RTLREADING+MB_OK
		.elseif wParam == 1004
			invoke GetWindowLong, hWnd, GWL_EXSTYLE
			mov ecx, WS_EX_LAYOUTRTL
			not ecx
			and eax, ecx 
			invoke SetWindowLong, hWnd, GWL_EXSTYLE, eax
			invoke InvalidateRect, hWnd, NULL, TRUE
			invoke MessageBox, hWnd, addr szConfirm, addr szAppName, MB_OK
		.elseif wParam == 1005
			invoke GetDlgItem, hWnd, 1002
			mov hControl, eax
			invoke GetWindowRect, hWnd, addr rcDialog
			invoke GetWindowRect, hControl, addr rcControl
			mov edi, rcControl.left
			sub edi, rcDialog.left
			mov esi, rcControl.top
			sub esi, rcDialog.top
			mov edx, rcControl.right
			sub edx, rcControl.left
			invoke MoveWindow, hControl, edi, esi, edx, 25, TRUE
		.elseif wParam == 1006
			invoke GetDlgItem, hWnd, 1002
			mov hControl, eax
			invoke GetWindowRect, hControl, addr rcControl
			invoke MapWindowPoints, NULL, hWnd, addr rcControl, 2
			mov edi, rcControl.left
			mov esi, rcControl.top
			add esi, 10
			mov edx, rcControl.right
			sub edx, rcControl.left
			invoke MoveWindow, hControl, edi, esi, edx, 25, TRUE
		.endif
	.elseif uMsg == WM_CLOSE
		invoke EndDialog,hWnd,0
		ret
	.endif
	xor eax, eax	
	ret
MainProc endp

end start
